//
//  WXPAuthQuestionVC.m
//  MexicoLoan
//
//  Created by WXP on 2025/2/27.
//
//

#import "WXPAuthQuestionVC.h"
#import "WXPAuthQuestionContentView.h"

@interface WXPAuthQuestionVC ()

@property (nonatomic, strong) WXPAuthQuestionContentView * viewContent;


@end

@implementation WXPAuthQuestionVC

#pragma mark - lazy
- (WXPAuthQuestionContentView *)viewContent{
    if (!_viewContent) {
        _viewContent = [WXPAuthQuestionContentView new];
        WEAKSELF
        _viewContent.blockResetAuthBtn = ^(BOOL clickable) {
            weakSelf.btnAuth.alpha = clickable ? 1 : 0.5;
            weakSelf.btnAuth.userInteractionEnabled = clickable;
        };
    }
    return _viewContent;
}

#pragma mark - viewDidLoad
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Page action:KEY_ENTER type:KEY_page];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Page action:KEY_OUT type:KEY_page];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    // 打点
    [GlobalMethod hitPointWithPageName:KEY_VerifyQuestion action:KEY_Enter extInfo:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navView resetViewWithTitle:@"Info de crédito"];
    [self.progressView resetViewWithNum:@"1"];
    [self.progressView.moneyView resetViewWithTag:0];
    [self resetHeaderView];
    WEAKSELF
    [self.btnAuth setNoRepeatActionWithInterval:1 action:^(UIButton * _Nonnull button) {
        [NSObject clickFeedback];
        [weakSelf.btnAuth addClickAnimate];
        [weakSelf requestSubmitAuth];
    }];
}

#pragma mark - resetHeaderView
- (void)resetHeaderView{
    self.headerView = [UIView initWithViews:@[
        self.progressView,
        [GlobalMethod getViewWithHeight:16],
        self.viewContent,
    ]];
    self.tableView.tableHeaderView = self.headerView;
}

#pragma mark - request
- (void)requestSubmitAuth{
    // 打点
     [GlobalMethod hitPointWithPageName:KEY_VerifyQuestion action:KEY_Save_Start extInfo:nil];
    NSDictionary * dic = @{
        KEY_overdue:        readStr(self.viewContent.overdue),
        KEY_overdueDays:    readStr(self.viewContent.overdueDays),
        KEY_totalOverdraft: readStr(self.viewContent.totalOverdraft),
        KEY_loanNumber:     readStr(self.viewContent.loanNumber),
        KEY_outstanding:    readStr(self.viewContent.outstanding),
    };
    [RequestApi requestSaveUserInfoWithData:dic step:KEY_CREDIT_INFO delegate:self success:^(NSDictionary * _Nonnull response, id  _Nonnull mark) {
    
        // 打点
         [GlobalMethod hitPointWithPageName:KEY_VerifyQuestion action:KEY_Save_End extInfo:nil];
        
        // 调用获取下一步接口，跳转到该接口返回的对应认证页面
        [self requestGetNextStep];
        
        // 风控
        [GlobalMethod addRiskControlWithType:KEY_QUESTIONNAIRE startTime:self.startTime endTime:[GlobalMethod getTimeStampMillisecond]];
        
    } failure:^(NSString * _Nonnull errorStr, id  _Nonnull mark) {
        
    }];
}

@end
